*** Paper: 			Does The World Trade Organization Enable Biosecurity and Trade for Importers and Exporters?
*** Authors: Linda Fernandez and Monica Das
*** Date:    		November 9, 2023
*** Last updated:   February 21, 2024
*** Description:	STATA codes for Tables 4 - 6 in the paper

******************************************************
********** Table 4 - 6 (BY AE/GDP)                ****
*******************************************************
///Download STATA file "wd.dta" from the Harvard Dataverse  
///Change directory to appropriate folder
//import STATA dataset "wd.dta" 
use "wd.dta", clear

gen AEcode = 0
egen median1 = median(AE_GDP)
replace AEcode = 1 if AE_GDP >= median1
replace AEcode = . if AE_GDP == .

///(Diversification)//////////////////////////////////
//// TABLE 4     ////////////////////////////////////

asdoc, row(\i, \i, \i) save(table 4) fs(16) font(Times New Roman) title(Random Coefficients Model Estimates: group-id Total Agricultural Exports/GDP Share) replace

xtrc AgrExport TACommlag Manu_sh lnRGDP , i( AEcode) betas

xtrc AgrExport TACommlag Manu_sh lnRGDP Diversification_Int resid_Div, i( AEcode) betas vce(bootstrap, reps(1000) seed(101016) dots(100))

matrix beta = e(beta_ps)
matrix B = beta'
matrix list B

matrix beta_se= e(V_ps)
matrix T = e(V_ps)'
matrix list T 

matrix C = J(36,2,0)

foreach i in 1 8 15 22 29 {
	foreach j in 1 2 {
		 matrix C[`i',`j']= sqrt(T[`i',`j'])
	}
}
        
matrix list C

matrix result_int = (B[1,1], B[1,2]\C[1,1], C[1,2]\ B[2,1], B[2,2]\C[8,1], C[8,2]\ B[3,1], B[3,2]\C[15,1], C[15,2]\B[4,1], B[4,2]\C[22,1], C[22,2]\B[5,1], B[5,2]\C[29,1], C[29,2] \B[6,1], B[6,2]\C[36,1], C[36,2])

asdoc, row(\i, \i, \i) save(table 4) fs(8) font(Times New Roman) title(\)
asdoc, row(Table, \i, \i) save(table 4) fs(8) font(Times New Roman) title(\) 	
asdoc, row(\i, Below Average, Above Average) save(table 4) fs(8) font(Times New Roman) title(\) 	
asdoc wmat, matrix(result_int) rnames(TACommlag se Manu_sh se lnRGDP se Diversification_Int se resid_Div se _cons se) cnames(AgrExportit AgrExportit) dec(2) fs(8) save(table 4) font(Times New Roman) title(\)


/////////////////////////////////////////////////
////(Duration)///////////////////////////////////////
/////////////////////////////////////////////////


//// TABLE 5     ////////////////////////////////////

asdoc, row(\i, \i, \i) save(table 5) fs(16) font(Times New Roman) title(Random Coefficients Model Estimates: group-id Total Agricultural Exports/GDP Share) replace

xtrc AgrExport TAduration Manu_sh lnRGDP Duration_Int resid_Dur, i( AEcode) betas vce(bootstrap, seed(101016) reps(1000) dots(100))

matrix beta = e(beta_ps)
matrix B = beta'
matrix list B


matrix beta_se= e(V_ps)
matrix T = e(V_ps)'
			
matrix C = J(36,2,0)

foreach i in 1 8 15 22 29 {
	foreach j in 1 2 {
		 matrix C[`i',`j']= sqrt(T[`i',`j'])
	}
}
        
matrix list C

matrix result_int = (B[1,1], B[1,2]\C[1,1], C[1,2]\ B[2,1], B[2,2]\C[8,1], C[8,2]\ B[3,1], B[3,2]\C[15,1], C[15,2]\B[4,1], B[4,2]\C[22,1], C[22,2]\B[5,1], B[5,2]\C[29,1], C[29,2] \B[6,1], B[6,2]\C[36,1], C[36,2])

asdoc, row(\i, \i, \i) save(table 5) fs(8) font(Times New Roman) title(\)
asdoc, row(Table, \i, \i) save(table 5) fs(8) font(Times New Roman) title(\) 	
asdoc, row(\i, Below Average, Above Average) save(table 5) fs(8) font(Times New Roman) title(\) 	
asdoc wmat, matrix(result_int) rnames(TAduration se Manu_sh se lnRGDP se Duration_Int se Residual se _cons se) cnames(AgrExportit AgrExportit) dec(2) fs(8) save(table 5) font(Times New Roman) title(\)

////////////////////////////////////////////
/////////////// (Value) ////////////////////////
////////////////////////////////////////////


//// TABLE 6     ////////////////////////////////////
asdoc, row(\i, \i, \i) save(table 6) fs(16) font(Times New Roman) title(Random Coefficients Model Estimates: group-id Total Agricultural Exports/GDP Share) replace

xtrc AgrExport lnTAvalue Manu_sh lnRGDP Value_Int resid_Value, i( AEcode) betas vce(bootstrap, reps(1000) seed(101016) dots(100))

matrix beta = e(beta_ps)
matrix B = beta'
matrix list B

matrix beta_se= e(V_ps)
matrix T = e(V_ps)'
			
matrix C = J(36,2,0)

foreach i in 1 8 15 22 29 {
	foreach j in 1 2 {
		 matrix C[`i',`j']= sqrt(T[`i',`j'])
	}
}
        
matrix list C

matrix result_int = (B[1,1], B[1,2]\C[1,1], C[1,2]\ B[2,1], B[2,2]\C[8,1], C[8,2]\ B[3,1], B[3,2]\C[15,1], C[15,2]\B[4,1], B[4,2]\C[22,1], C[22,2]\B[5,1], B[5,2]\C[29,1], C[29,2] \B[6,1], B[6,2]\C[36,1], C[36,2])

asdoc, row(\i, \i, \i) save(table 6) fs(8) font(Times New Roman) title(\)
asdoc, row(Table, \i, \i) save(table 6) fs(8) font(Times New Roman) title(\) 	
asdoc, row(\i, Below Average, Above Average) save(table 6) fs(8) font(Times New Roman) title(\) 	
asdoc wmat, matrix(result_int) rnames(lnTAvalue se Manu_sh se lnRGDP se Value_Int se Residual se _cons se) cnames(AgrExportit AgrExportit) dec(2) fs(8) save(table 6) font(Times New Roman) title(\)



